package com.enjoyor.soa.traffic.rest.efoms.controller;

import com.enjoyor.soa.traffic.api.dto.efoms.EvalItemInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.RepairsInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IEvalItemConsumeService;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Auth
@RestController
@RequestMapping({ "/evalItem" })
@Api("DevStatusController")
@CrossOrigin
public class EvalItemController {

    @Autowired
    private IEvalItemConsumeService evalItemConsumeService;

    /**
     * 新增评价项
     *
     * @param evalItemInfoDto
     * @param request
     */
    @PostMapping(value = { "/insertEvalItem" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiResponse(response=EvalItemInfoDto.class, code = 0, message = "")
    @ApiOperation("新增评价项")
    public ResultPojo insertEvalItemInfo(@RequestBody EvalItemInfoDto evalItemInfoDto,HttpServletRequest request) {
        return evalItemConsumeService.insertEvalItemInfo(evalItemInfoDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 修改评价项
     *
     * @param evalItemInfoDto
     * @param request
     */
    @PutMapping(value = { "/updateEvalItem" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiResponse(response=EvalItemInfoDto.class, code = 0, message = "")
    @ApiOperation("修改评价项")
    public ResultPojo updateEvalItemInfo(@RequestBody EvalItemInfoDto evalItemInfoDto, HttpServletRequest request) {
        return evalItemConsumeService.updateEvalItemInfo(evalItemInfoDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 删除评价项
     *
     * @param evalItemId
     * @param request
     */
    @DeleteMapping(value = { "/deleteEvalItem" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除评价项")
    @ApiImplicitParam(name = "evalItemId", value = "evalItemId", paramType = "query", required = true, dataType = "String")
    public ResultPojo deleteEvalItemInfo(@RequestParam("evalItemId")String evalItemId, HttpServletRequest request) {
        return evalItemConsumeService.deleteEvalItemInfo(evalItemId,((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

    /**
     * 查询评价项
     *
     * @param evalItemId
     * @return
     */
    @GetMapping(value = { "getEvalItemList" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiResponse(response = RepairsInfoDto.class, code = 0, message = "")
    @ApiOperation("查询评价项")
    @ApiImplicitParam(name = "evalItemId", value = "评价项编号", paramType = "query", dataType = "String")
    public ResultPojo getEvalItemList(
            @RequestParam(value = "evalItemId", required = false)String evalItemId,HttpServletRequest request) {
        return evalItemConsumeService.getEvalItemList(evalItemId);
    }

}
